package com.yc.snacknet_vue.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yc.snacknet_vue.bean.MemberInfo;
import com.yc.snacknet_vue.biz.IOrderInfoBiz;
import com.yc.snacknet_vue.biz.Impl.OrderInfoBizImpl;
import com.yc.snacknet_vue.utils.SessionKeys;
import com.yc.snacknet_vue.utils.StringUtil;

/**
 * 订单业务控制层
 * @author UNO
 * @date 2021年8月13日
 * Email 2759451734@qq.com
 */
@WebServlet("/order/*")
public class OrderInfoController extends BaseServlet {

	private static final long serialVersionUID = 5832330514160026162L;

	//下订单
	protected void add(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		String cnos = request.getParameter("cnos"); //购物车编号
		String ano = request.getParameter("ano"); //购物车编号
		String price = request.getParameter("price"); //购物车编号

		if(StringUtil.checkNull(cnos, ano, price)) {
			this.send(response, 101, ""); //参数不全
			return;
		}
		IOrderInfoBiz biz = new OrderInfoBizImpl();
		//开始下订单
		String result = biz.add(cnos, ano, price);  //返回订单编号
		if(StringUtil.checkNull(result)) {
			this.send(response, 500, null); //下单失败
			return;
		}
		this.send(response, 200, result);
	}

	protected void findByMno(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		Object obj = request.getSession().getAttribute(SessionKeys.CURRENTMEMLOGINACCOUNT);	
		if( null == obj) {
			this.send(response, 501, null); //说明未登录
			return;
		}
		MemberInfo mem = (MemberInfo) obj;
		IOrderInfoBiz biz = new OrderInfoBizImpl();
		List<Map<String, Object>> list = biz.findByMno(String.valueOf(mem.getMno()));
		if(null == list || list.isEmpty()) {
			this.send(response, 500, null); 
			return;
		}
		this.send(response, 200, list);
		
		
	}

}
